package com.zaozhuang.robot.websocket;

import static android.content.Context.ACTIVITY_SERVICE;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.IBinder;
import android.os.Build;

/**
 * @author September
 * @package com.cmri.tvdemo.utils
 * @date 2020/6/10
 * @desc <>
 */
public class ServiceUtils {
    public static Intent socketIntent;

    //开启待办服务连接socket
    public static void startWebSocketService(Activity activity, String token, String url) {
        // 启动服务并设置为前台服务
        Intent socketIntent = new Intent(activity, socketService.class);
        socketIntent.putExtra("token", token);
        socketIntent.putExtra("url", url);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // Android 8.0 及以上版本使用 startForegroundService
            activity.startForegroundService(socketIntent);// 将服务设置为前台服务并关联通知
        } else {
            // Android 8.0 以下版本使用 startService
            activity.startService(socketIntent);
        }
//        socketIntent = new Intent(activity, socketService.class);
//        socketIntent.putExtra("token", token);
//        socketIntent.putExtra("url", url);
//        activity.startService(socketIntent);
    }

    //    退出待办服务断开socket
    public static void stopWebSocketService(Activity activity) {
        if (socketIntent != null) {
            activity.stopService(socketIntent);
        }
    }

}
